package com.aita.diamond.service

import com.gd.magic.Service
import com.gd.magic.util.StringUtil

import com.gd.domain.party.Organization
import com.gd.domain.party.Operator
 
import org.hibernate.Query

import java.text.*
import com.aita.diamond.Order
import com.aita.diamond.VIPCustomer


class VIPCustomerService implements Service {

	public static final String FORMAT_YEARMONTH = "yyyy-MM-dd"
	def loadCustomer(long id){
		def now = new Date();
		VIPCustomer customer = VIPCustomer.load(id)
		assert customer : X("未找到"+ id)
		def result = [customer:customer,operName:customer.oper.name]
		return result;
	}
	
	def saveCustomer(VIPCustomer customer){
		assert customer: X("用户信息为空")
		assert customer.name: X("用户姓名为空")
		if(customer.id == null)//新增
		{
			customer.oper = loginService.currentOperator()
			customer.org = loginService.currentOrg()
			customer.regDate = new Date()
			
			def e = VIPCustomer.loadByphone(customer.phone)
			assert e == null : X("客户信息已存在")
		}
	
		logService.log(customer.id == null ?101030:101031 ,(customer.id== null ?"新增":"修改") +"客户信息(" + customer.phone +")")
		customer.persistOrMerge()

	}
	
	//校验客户是否存在
	def checkCustomerExist(String phone){
		def customer = VIPCustomer.loadByphone(phone)
		return [customer:customer];
	}
	
}